// Ninf-G-XX, ver. 0.1
// Copyright 2011 National Institute of Advanced Industrial Science and Technology
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
 * $URL$
 * $AIST_Release$
 * $AIST_Copyright$
 */

#ifndef _GRPC_DATA_H_
#define _GRPC_DATA_H_
#include "grpc.h"

typedef enum grpc_data_type_e {
    GRPC_INT,     /* integer */
    GRPC_DOUBLE,  /* double */
    GRPC_COMPLEX,  /* complex */
    GRPC_STRING ,  /* string */
    GRPC_FILE,  /* file */
    GRPC_ARRAY_OF_INT,  /* array of int */
    GRPC_ARRAY_OF_DOUBLE,  /* array of double */
    GRPC_ARRAY_OF_COMPLEX,  /* array of complex */
    GRPC_MATRIX_OF_INT,  /* matrix of int */
    GRPC_MATRIX_OF_DOUBLE,  /* matrix of double */
    GRPC_MATRIX_OF_COMPLEX,  /* matrix of complex */
    GRPC_CONTAINER_OF_GRPC_DATA,  /* container of grpc_data_t */
} grpc_data_type_t;


typedef enum grpc_data_mode_e {
	GRPC_VOLATILE,
    GRPC_UNIQUE_VOLATILE,
    GRPC_PRESISTENT,
    GRPC_STICKY,
    GPRC_UNIQUE_STICKY,
    GRPC_END_LIST,
} grpc_data_mode_t;

/**
typedef enum grpc_data_resolution_mode_e {
	GRPC_RESULT_RETURN,
  GRPC_NO_RESULT,
	GRPC_RESULT_DEFAULT,
} grpc_data_resolution_mode_t;
*/

typedef enum grpc_completion_mode_e {
	GRPC_WAIT_ALL,
	GRPC_WAIT_ANY
} grpc_completion_mode_t;

typedef enum grpc_data_diffusion_e {
	GRPC_DEFAULT_DIFFUSION,
	GRPC_UNICAST,
	GRPC_BROADCAST,
} grpc_data_diffusion_t;

typedef enum grpc_data_info_type_e {
	GRPC_HANDLE,
	GRPC_INPUT_URI,
	GRPC_OUTPUT_URI,
	GRPC_MANAGEMENT_MODE,
	GRPC_SIZE,
	GRPC_DATA_TYPE,
	GRPC_LOCATIONS_LIST,
	GRPC_STATUS,
	GRPC_COHERENT,
} grpc_data_info_type_t;


typedef struct grpc_data_s {
	void * realhandle;
} grpc_data_t;

/******************************************************************/
/*                           functions                            */
/******************************************************************/

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/**
 * initialize function for data handles
 * - data should be allocated by users
 * - list of URIs are NULL terminated list
 * - variable_configuration will be 0 terminated array
 *   like [3, 3, 0]
 */

grpc_error_t
grpc_data_init(
  grpc_data_t            * data,
	const char            ** list_of_URI_input,
	const char            ** list_of_URI_output,
	const grpc_data_type_t   variable_type,
  const size_t           * variable_configuration,
	const grpc_data_mode_t * list_of_data_mode
);



grpc_error_t
grpc_data_memory_mapping_set(
  const char * key,
	void       * ptr
);


grpc_error_t
grpc_data_memory_mapping_get(
	const char * key,
	void      ** ptr
);

grpc_error_t
grpc_data_container_set(
	grpc_data_t * container,
	const int rank,
  const grpc_data_t * data
);

grpc_error_t
grpc_data_container_get(
  const grpc_data_t * container,
	const           int rank,
  grpc_data_t      ** data
);

grpc_error_t
grpc_data_transfer(
  grpc_data_t * data,
  const char ** list_of_input_URI,
  const char ** list_of_output_URI,
  const grpc_data_mode_t * list_of_input_modes,
  const grpc_data_mode_t * list_of_output_modes
);

grpc_error_t
grpc_data_wait(
	const grpc_data_t ** list_of_data,
	grpc_completion_mode_t mode
);

grpc_error_t
grpc_data_unbind(
	grpc_data_t * data
);

grpc_error_t
grpc_data_free(
  grpc_data_t * data,
	const char ** const URI_locations
);

grpc_error_t
grpc_data_getinfo(
  const grpc_data_t * data,
	const grpc_data_info_type_t info_tag,
	const char * URI,
	char ** info
);

grpc_error_t
grpc_data_load(
  grpc_data_t * data,
	const char * URI_input
);

grpc_error_t
grpc_data_save(
  const grpc_data_t * data,
	const char * URI_output
);

#ifdef __cplusplus
}
#endif /* __cplusplus */


#endif /* _GRPC_DATA_H_ */
